$(function(){ 
    
   
    
    $("#dsh,#ytg,#ywc,#wtg").click(function(){
        var act_type=this.id;//四种点击事件的判断
        if(act_type=='dsh'){
              var status=-1;
        }else if(act_type=='ytg'){
              var status=1;
        }else if(act_type=='wtg'){
              var status=2;
        }else if(act_type=='ywc'){
              var status=3;
        }
		    var mysy_list=myconfig['api']+'getorderlists';
        var userid=myinfo['userid'];
        var random=myinfo['random'];
        var mod='trial';
        var htms='';
		if(userid&&random){	
            $.post(mysy_list, {userid:userid,random:random,mod:mod,status:status},function(data,status){
              if(data.status==1){
                console.debug(data);
                //待审核
                $.each(data.lists,function(key,item){
                   var money=parseInt(item.goods_price)+parseInt(item.goods_bonus);
                   if(item.qq==0){ item.qq='该商家没有绑定QQ';}
                   htms+='<li>';
                   if(act_type=='dsh'){
                   
                   }
                   htms+='<div class="trial_order_listL">';
                   htms+='<img src='+myconfig["url"]+item.thumb+'>';
                   if(act_type=='dsh'){
                   htms+='<div class="fqsq" id="fqsq">放弃申请</div>';
                   htms+='<input type="hidden" value='+item.id+'>';
                   }else if(act_type=='ytg'){
                    if(item.status==2){
                   htms+='<div class="txdd" >填写订单</div><input type="hidden" value='+item.id+'></input>';
                    }
                   }
                   htms+='</div>';
                   htms+='<div class="trial_order_listR">';
                   htms+='<div class=" yc">'+item.title+'</div>';
                   if(act_type=='dsh'){
                   htms+='<div class="trial_order_taobao">绑定的淘宝：<b>'+item.taobao_account+'</b></div>';
                   }else{
                   htms+='<div >商家QQ：<b>'+item.qq+'</b></div>';
                   }
                   htms+='<div >下单价：<b>￥'+item.goods_price+'</b></div>';
                   htms+='<div >返还：<b>￥'+money+'</b>（含红包<b>￥'+item.goods_bonus+'</b>）</div>';
                   if(act_type=='dsh'||act_type=='ytg'){
                   htms+='<div >审核申请中：<b><span id="day_show'+key+'"></span><span id="hour_show'+key+'"></span><span id="minute_show'+key+'"></span><span id="second_show'+key+'"></span></b></div>';
                   }else if(act_type=='wtg'){
                   htms+='<div>订单状态：<b>'+item.cause+'</b></div>';
                   }
                   htms+='</div>';
                   if(act_type=='dsh'){
                  
                   }
                   htms+='</li>';
                   var insertNode=act_type+'L';
                   $('#'+insertNode).children().remove();
                   $('#'+insertNode).append(htms);
                   var start_time=data.lists[key].inputtime;
          
                   $.ajax({ 
                      type:'get',  
                      url : myconfig['api']+'get_activity_config',  
                      dataType : 'json',  
                      jsonp:"jsoncallback",  
                      success  : function(data) {  
                            if(act_type=='ytg'){
                              check_time=data.data.seller_give_back;
                            }else{
                              check_time=data.data.seller_check_time; 
                            }
                                                    
                            timer(key,start_time,act_type);
                      },
                      error: function() {  
                        alert('获取活动设置失败');  
                      },  
                   });

                   
                   //填写订单号   
                   $(".txdd").click(function(){
                      var order_id=$(this).next().val();
                      $(".popup").fadeIn();
                      $(".input_yes").click(function(){
                        var order_number=$('#ddh').val();
                        $.ajax({ 
                                data:{userid:userid,order_id:order_id,order_sn:order_number,random:random},
                                type:'post',  
                                url : myconfig['api']+'fill_order_sn',  
                                dataType : 'json',  
                                jsonp:"jsoncallback",  
                                success  : function(data) {  
                                          art.dialog({
                                              fixed: true,
                                              title: '提示',
                                              content: data.msg,
                                              ok: function(){                                                                                
                                                location.reload();                                                
                                              },                                       
                                          });                                                                    

                                },
                                error: function() {  
                                    
                                },  
                             });
                      })
                   });
  
  

           


                });

                      //点击“放弃申请”
                   $(".fqsq").click(function(){
                       
                       //如果没有登录信息
                      if(!(myinfo['userid'] && myinfo['random'])){
                        location.href='../user/login.html';
                      }
                      //获取订单ID
                      var order_id=$(this).next().val();
                      art.dialog({
                                    fixed: true,
                                    title: '提示',
                                    content: '你确定要放弃申请？',
                                    ok: function(){
                                      //发送ajax请求删除
                                      $.ajax({ 
                                          data:{order_id:order_id,userid:userid,random:random},
                                          type:'post',  
                                          url : myconfig['api']+'close_order_sn',  
                                          dataType : 'json',  
                                          jsonp:"jsoncallback",  
                                          success  : function(data) {  
                                              location.reload();
                                                
                                          },
                                          error: function() {                              
                                            
                                          },  
                                      });

                                    },
                                    cancel:true,

                                 });
                      
                      
　　　　           });             


              }else{
                //提示获取数据失败
              }
                 
		},'json');}else{
			window.location.href='./user/login.html';
		}
									
  })

//页面默认显示待审核的数据
        var mysy_list=myconfig['api']+'getorderlists';
        var userid=myinfo['userid'];
        var random=myinfo['random'];
        var mod='trial';
        var htms='';
if(userid&&random){ 
            $.post(mysy_list, {userid:userid,random:random,mod:mod,status:-1},function(data,status){
              if(data.status==1){
                //待审核

                $.each(data.lists,function(key,item){
                   
                   var money=parseInt(item.goods_price)+parseInt(item.goods_bonus);
                   htms+='<li>'
                   
                   htms+='<div class="trial_order_listL">';
                   htms+='<img src='+myconfig["url"]+item.thumb+'>';
                   htms+='<div class="fqsq" id="fqsq">放弃申请</div>';
                   htms+='<input type="hidden" value='+item.id+'>';
                   htms+='</div>';
                   htms+='<div class="trial_order_listR">';
                   htms+='<div class=" yc">'+item.title+'</div>';
                   htms+='<div class="trial_order_taobao">绑定的淘宝：<b>'+item.taobao_account+'</b></div>';
                   htms+='<div >下单价：<b>￥'+item.goods_price+'</b></div>';
                   htms+='<div >返还：<b>￥'+money+'</b>（含红包<b>￥'+item.goods_bonus+'</b>）</div>';
                   htms+='<div >审核申请中：<b><span id="day_show'+key+'"></span><span id="hour_show'+key+'"></span><span id="minute_show'+key+'"></span><span id="second_show'+key+'"></span></b></div>';
                   htms+='</div>';
                   htms+='</li>';
                   var insertNode='dshL';
                   $('#'+insertNode).children().remove();
                   $('#'+insertNode).append(htms); 
                   var start_time=data.lists[key].inputtime;
                  
                   $.ajax({ 
                      type:'get',  
                      url : myconfig['api']+'get_activity_config',  
                      dataType : 'json',  
                      jsonp:"jsoncallback",  
                      success  : function(data) {  
                            
                            check_time=data.data.seller_check_time;                         
                            timer(key,start_time,act_type='dsh');//定时刷新剩余时间
                      },
                      error: function() {  
                        alert('获取活动设置失败');  
                      },  
                   });

                   


                });
                  

                    //点击“放弃申请”
                   $(".fqsq").click(function(){
                       //如果没有登录信息
                      if(!(myinfo['userid'] && myinfo['random'])){
                        location.href='../user/login.html';
                      }
                      //获取订单ID
                      var order_id=$(this).next().val();
                      art.dialog({
                                    fixed: true,
                                    title: '提示',
                                    content: '你确定要放弃申请？',
                                    ok: function(){
                                      //发送ajax请求删除
                                      $.ajax({ 
                                          data:{order_id:order_id,userid:userid,random:random},
                                          type:'post',  
                                          url : myconfig['api']+'close_order_sn',  
                                          dataType : 'json',  
                                          jsonp:"jsoncallback",  
                                          success  : function(data) {  
                                              location.reload();
                                                
                                          },
                                          error: function() {                              
                                            
                                          },  
                                      });

                                    },
                                    cancel:true,

                                 });
                      
                      
　　　　           });             

     

              }else{
               
              }
                 
    },'json');}else{
      window.location.href='./user/login.html';
    }

})

function timer(key,start_time,act_type){
    
    tim=window.setInterval(function(){
    //拼接元素
    var day_show=act_type+'L #day_show'+key;
    var hour_show=act_type+'L #hour_show'+key;
    var minute_show=act_type+'L #minute_show'+key;
    var second_show=act_type+'L #second_show'+key;

    var intDiff=parseInt(start_time)+parseInt(check_time*3600*24)-parseInt(new Date().getTime()/1000);
    var day=0,
        hour=0,
        minute=0,
        second=0;//时间默认值        
    if(intDiff > 0){
        day = Math.floor(intDiff / (60 * 60 * 24));
        hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
        minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
        second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
    
        if (minute <= 9) minute = '0' + minute;
        if (second <= 9) second = '0' + second;    
        $('#'+day_show).html(day+"天");
        $('#'+hour_show).html(''+hour+'时');
        $('#'+minute_show).html(''+minute+'分');
        $('#'+second_show).html(''+second+'秒');
        
    }else{
        $('#'+day_show).html('订单');
        $('#'+hour_show).html('已');
        $('#'+minute_show).html('关');
        $('#'+second_show).html('闭');

    }

    }, 1000);
} 

                                                           
                             